package com.glory.hikvisionmobile.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.glory.hikvisionmobile.R;
import com.glory.hikvisionmobile.bean.EqpWork.EqpStateInfo;
import com.glory.hikvisionmobile.customView.HikLabelSpinner;
import com.glory.hikvisionmobile.customView.HikLabelSpinner2;

import java.util.ArrayList;
import java.util.List;

/**
 * *****************************
 *
 * @Anthor yazhou
 * @Email 1184545990@qq.com
 * @Time 2020/3/16 16:36
 * @DESC *****************************
 */
public class EqpEventSpinnerAdapter extends HikLabelSpinner2.HikSpinnerAdapter {

    private List<EqpStateInfo.XPdaEventsBean> _Data;

    public EqpEventSpinnerAdapter(List<EqpStateInfo.XPdaEventsBean> data) {
        if (_Data == null) {
            _Data = new ArrayList<>();
        }
        if (data != null) {
            this._Data.addAll(data);
        }
    }

    public void setData(List<EqpStateInfo.XPdaEventsBean> data) {
        this._Data.clear();
        if (data != null) {
            this._Data.addAll(data);
        }
        notifyDataSetChanged();
    }

    private String _item(EqpStateInfo.XPdaEventsBean bean) {
        return String.format("%1$s/%2$s", bean.getEventId(), bean.getDescription());
    }

    @Override
    public int getCount() {
        return _Data.size();
    }

    @Override
    public EqpStateInfo.XPdaEventsBean getItem(int position) {
        return _Data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.hik_item_spinner, parent, false);
        }
        ((TextView)convertView.findViewById(R.id.tv_label)).setText(_item(_Data.get(position)));
        return convertView;
    }

    @Override
    public CharSequence getSelectedDesc(int position) {
        return _item(_Data.get(position));
    }
}
